/* ChatActivity.java
 *
 * Copyright 2011 Aleksey Konovalov
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 * 
 */

package org.jimm.engine;

import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.format.Time;
import android.text.style.ForegroundColorSpan;

/** ��������� � ������� ���������
 * 
 * @author ������� ��������� (aleks_dsp)
 *
 */
public final class Message {

	private static final ForegroundColorSpan incomingMessageForegroundColorSpan = new ForegroundColorSpan(Color.LTGRAY);
	private static final ForegroundColorSpan outgoingMessageForegroundColorSpan = new ForegroundColorSpan(Color.YELLOW);
	
	String text;
	Time time;
	boolean received;
	
	public Message(String text, Time time, boolean received) {
		this.text = text;
		if(time != null)
			this.time = new Time(time);
		else {
			this.time = new Time();
			this.time.setToNow();
		}
		this.received = received;
	}
	
	public Spannable toSpannable() {
		String dataString = time.format("%d.%m.%Y %H:%M:%S : ");
		SpannableString result = new SpannableString(dataString + text);
		result.setSpan(received ? incomingMessageForegroundColorSpan : outgoingMessageForegroundColorSpan,
				0, result.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		return result;
	}
	
	public Time getTime() {
		return time;
	}
	
	public boolean isReceived() {
		return received;
	}
	
	public String getText() {
		return text;
	}

}
